﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RoccaStore.Data.Entity.Model;

namespace RoccaStore.Data.Entity.Entities
{
    public class FileInfoEntities : EntitiesBase<RoccaStoreEntities>, IFileInfoRepository
    {
        public FileInfo GetByID(int id)
        {
            return Context.FileInfo
                .FirstOrDefault(i => i.ID == id);
        }

        public FileInfo GetBySlug(string slug)
        {
            return Context.Slug
                .Include("File")
                .FirstOrDefault(s => s.Name == slug).File;
        }

        public List<FileInfo> GetByFileSendID(int fileSendId)
        {
            return new List<FileInfo>();
        }

        public int Save(FileInfo fileInfo)
        {
            if(fileInfo.ID == 0)
                Context.FileInfo.Add(fileInfo);

            Context.SaveChanges();
            return fileInfo.ID;
        }
    }
}
